﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mask : MonoBehaviour
{

    public int stencilRef = 1;
    public UISprite uISprite;
    public BoxCollider boxCollider;
    public float horizontalSpacing = 0;
    public float verticalSpacing = 0;
    [Range(0, 2)]
    public float ratios = 0.95f;

    void Start()
    {
        Vector2 m_size = Vector2.zero;
        Vector3 m_pos = Vector3.zero;
        if (uISprite != null)
        {
            m_pos = uISprite.transform.position;
            m_size = new Vector2(uISprite.width, uISprite.height);

        }
        else if (boxCollider != null)
        {
            m_pos = boxCollider.transform.position;
            m_size = new Vector2(boxCollider.size.x, boxCollider.size.y);
        }

        Vector3 pos = base.transform.position;
        base.transform.localScale = new Vector3(m_size.x * ratios - horizontalSpacing * 2, m_size.y * ratios - verticalSpacing * 2, 1);
        base.transform.position = new Vector3(m_pos.x, m_pos.y, pos.z);

        base.gameObject.GetComponent<MeshRenderer>().material.SetInt("_StencilRef", stencilRef);
    }

}
